/**   
* @Title: XmlParser.java
* @Package org.xaoyaoyao.spider.parser
* @Description: TODO
* @author xaoyaoyao
* @date Jan 25, 2019 11:26:38 AM
* @version V1.0   
*/
package org.xaoyaoyao.spider.parser;

import org.apache.commons.lang3.StringUtils;
import org.xaoyaoyao.spider.html.InfoExtractorUtil;
import org.xaoyaoyao.spider.xstream.XStreamUtil;

import lombok.Builder;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName: XmlParser
 * @Description: TODO
 * @author xaoyaoyao
 * @date Jan 25, 2019 11:26:38 AM
 * 
 */
@Slf4j
@Builder
public class XmlParser {

	/** html文本 **/
	private String htmlTxt;

	/** 模板 **/
	private String xslt;

	public <T> T parse(Class<T> clazz) {
		log.debug(">>>>>>>> htmlTxt >> {}", htmlTxt);
		log.debug(">>>>>>>> xslt >> {}", xslt);
		if (StringUtils.isBlank(htmlTxt)) {
			log.error(">>>>>>>> Html text is empty！！！");
			return null;
		}
		if (StringUtils.isBlank(xslt)) {
			log.error(">>>>>>>> XML template is empty！！！");
			return null;
		}
		String xml = InfoExtractorUtil.transform(htmlTxt, xslt);
		log.debug(">>>>>>>> xml >> {}", xml);
		return XStreamUtil.xmlToBean(xml, clazz);
	}
}
